package com.isoftstone.service.Impl;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.isoftstone.dao.UserDao;
import com.isoftstone.entity.Users;
import com.isoftstone.service.UserService;


@Service("UserService")
public class UserServiceImp implements UserService {
	@Autowired
	private UserDao userDao;
	
	
	
	@Override
	public List<Users> getAllUserList() {
		// TODO Auto-generated method stub
		List<Users> list=userDao.getAllUserList();
		return list;
	}
	@Override
	public boolean insertUser(Users users) {
		// TODO Auto-generated method stub
		if(users!=null && !"".equals(users.getUser_id())){
			boolean flag =userDao.insertUser(users);
			if(flag){
				if(users.getRole()!=null && !"".equals(users.getRole().getRole_id())){
					boolean flag1 =userDao.insertUserRole(users.getUser_id(),users.getRole().getRole_id());
					if(flag1){
						return true;
					}
				}
					
			}
			
		}
		return false;
		
	}
	@Override
	public boolean deleteUser(String user_id) {
		// TODO Auto-generated method stub
		if(user_id!=null ){
			boolean flag =userDao.deleteUser(user_id);
			if(flag){
					boolean flag1 =userDao.deleteUserRole(user_id);
					if(flag1){
						return true;
					}
				
					
			}
			
		}
		return false;
	}
	@Override
	public boolean editUser(Users users) {
		// TODO Auto-generated method stub
		if(users!=null && !"".equals(users.getUser_id())){
			boolean flag =userDao.editUser(users);
			if(flag){
				if(users.getRole()!=null && !"".equals(users.getRole().getRole_id())){
					boolean flag1 =userDao.editUserRole(users.getUser_id(),users.getRole().getRole_id());
					if(flag1){
						return true;
					}
				}
					
			}
			
		}
		return false;
	}
	@Override
	public Users getUserByUserName(String user_id) {
		// TODO Auto-generated method stub
		if(user_id!=null ){
			Users user =userDao.getUserByUserName(user_id);
			
			return user;
		}
		return null;
	}
	

}
